package com.tang.script;

import com.tang.script.command.CacheCommandManager;
import com.tang.script.command.ScriptCommandBuilder;
import com.tang.script.functions.FunctionLoader;
import com.tang.script.result.DefaultScriptResult;
import com.tang.script.result.ScriptResult;
import lombok.Getter;
import lombok.Setter;

import javax.script.CompiledScript;
import java.net.URI;
import java.util.Objects;

@Getter
@Setter
public class DefaultScriptEngine implements ScriptEngine {
    ScriptCommandBuilder scriptCommandBuilder;
    FunctionLoader functionLoader;
    CacheCommandManager cacheCommandManager;
    SystemVariableContainer systemVariableContainer;

    @Override
    public <T> ScriptResult<T> executeScript(ScriptCommand<T> script) {
        script.setScriptEngine(this);
        return DefaultScriptResult.of(script.execute());
    }

    @Override
    public CompiledScript getScript(String key, String scriptText) {
        return cacheCommandManager.getScript(key, scriptText);
    }

    @Override
    public Object loadFunction(String functionName) {
        return functionLoader.loadFunction(functionName);
    }
}
